//
//  TextFieldViewController.m
//  TextField
//

#import "TextFieldViewController.h"

@implementation TextFieldViewController

- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string {
	
	// 10 글자까지만 입력 받는다.
	int MAX_CHARS = 10;
	NSMutableString *newText
	= [NSMutableString stringWithString:textField.text];
	[newText replaceCharactersInRange:range withString:string];
	return ([newText length] <= MAX_CHARS);
}

- (void)viewDidLoad {
    [super viewDidLoad];

	CGRect textRect = CGRectMake(10, 10, 300, 26);
	UITextField *myTextField = [[UITextField alloc] initWithFrame:textRect];
	myTextField.delegate = self;
	myTextField.borderStyle = UITextBorderStyleRoundedRect;

	myTextField.font = [UIFont systemFontOfSize:22.0];
	myTextField.adjustsFontSizeToFitWidth = YES;
	myTextField.minimumFontSize = 2.0;
	
	myTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
	myTextField.keyboardType = UIKeyboardTypeDefault;
	myTextField.autocorrectionType = UITextAutocorrectionTypeNo;
	myTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
	myTextField.returnKeyType = UIReturnKeyDone;
	
	[myTextField becomeFirstResponder];

	[self.view addSubview:myTextField];
	[myTextField release];
}

- (void)dealloc {
    [super dealloc];
}

@end
